from commands import add, admin
from pyspades.serverloaders import PositionData
import commands
     
@admin
def lava(connection):
    if connection.protocol.lava == True:
        connection.protocol.send_chat('Lava is now off.')
        connection.protocol.lava = False
    else:
        if connection.protocol.lava is None:
            connection.protocol.lava = set()
        connection.protocol.send_chat('Lava is now on.')
        connection.protocol.lava = True
add(lava)
 
def apply_script(protocol, connection, config):
    position_data = PositionData()
    class LavaConnection(connection):
        def on_update_position(self):
            if self.world_object.position.z > 61.0 and self.protocol.lava == True:
                self.kill()
                self.send_chat('You stepped in Lava.')
            return connection.on_update_position(self)
    class LavaProtocol(protocol):
        lava = None
    return LavaProtocol, LavaConnection